-
Notifications
You must be signed in to change notification settings - Fork 573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modernize StripeConfiguration #1485
Conversation
@@ -50,10 +50,6 @@ | |||
<PackageReference Include="System.Collections.Immutable" Version="1.5.0" /> | |||
</ItemGroup> | |||
|
|||
<PropertyGroup Condition=" '$(TargetFramework)' == 'net45' "> | |||
<DefineConstants>$(DefineConstants);NET45</DefineConstants> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out this wasn't needed. Preprocessor constants are automatically defined for the target framework: https://docs.microsoft.com/en-us/dotnet/standard/frameworks#how-to-specify-target-frameworks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay this all looks fine to me, but I have some comments (likely me misunderstanding some of it). Usual "I'm wary of reviewing such core changes, but not sure you have an alternative today)
@@ -35,7 +35,7 @@ You can configure the Stripe.net package to use your secret API key in one of tw | |||
a) In your application initialization, set your API key (only once once during startup): | |||
|
|||
```csharp | |||
StripeConfiguration.SetApiKey("[your api key here]"); | |||
StripeConfiguration.ApiKey = "[your api key here]"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this remove SetApiKey
entirely? Isn't this a breaking change? Or are we just making this cleaner but still supporting both (flagging now since it's the first thing in the review)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My intention was to avoid a breaking change by keeping the old methods around, but marking them as Obsolete
to encourage users to upgrade to the new way of setting these values, and actually remove the methods in a future major version. This would make the upgrade a bit less painful for users.
I don't feel too strongly about it, if you'd rather we drop the old methods immediately that's fine by me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I think that's fine and a nicer experience for sure
/// <remarks> | ||
/// You can also set the API key using the <c>StripeApiKey</c> key in | ||
/// <see cref="System.Configuration.ConfigurationManager.AppSettings"/>. | ||
/// </remarks> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel weird about preprocessor commands + comments. Isn't it better to document it globally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that we can't link to System.Configuration.ConfigurationManager.AppSettings
with .NET Standard 1.2 because the class doesn't exist. I could just remove the link or the comment entirely, but it's kind of a shame.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah I see what you mean. Ugh. Sounds good then!
/// <see cref="HttpTimeout"/> property instead. | ||
/// </summary> | ||
// TODO: remove this property in a future major version | ||
[Obsolete("Use StripeConfiguration.HttpTimeout instead.")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're already merging in a major version. Why not just do it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
} | ||
|
||
// TODO: remove everything below this in a future major version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, you're already planning version 23, why not do it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
@@ -120,7 +117,7 @@ private static async Task<StripeResponse> ExecuteRequestAsync(HttpRequestMessage | |||
|
|||
internal static HttpRequestMessage GetRequestMessage(string url, HttpMethod method, RequestOptions requestOptions) | |||
{ | |||
requestOptions.ApiKey = requestOptions.ApiKey ?? StripeConfiguration.GetApiKey(); | |||
requestOptions.ApiKey = requestOptions.ApiKey ?? StripeConfiguration.ApiKey; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay minor but need to flag: there's no thread safety and such, which I think is okay, but removing a getter prevents from ever adding this right? Though I guess it still has a getter/setter associated with it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow. The only thing that changed with regards to the global API key is that StripeConfiguration.GetApiKey()
is now StripeConfiguration.ApiKey
and StripeConfiguration.SetApiKey(newKey)
is now Stripe.Configuration.ApiKey = newKey
.
Changing the global API key was never thread-safe. Users that want to use different API keys in a multi-threaded environment must set the API key per request via RequestOptions
.
cbc8b5a
to
2e45d6a
Compare
2e45d6a
to
204f0f1
Compare
ptal @remi-stripe |
@@ -35,7 +35,7 @@ You can configure the Stripe.net package to use your secret API key in one of tw | |||
a) In your application initialization, set your API key (only once once during startup): | |||
|
|||
```csharp | |||
StripeConfiguration.SetApiKey("[your api key here]"); | |||
StripeConfiguration.ApiKey = "[your api key here]"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I think that's fine and a nicer experience for sure
/// <remarks> | ||
/// You can also set the API key using the <c>StripeApiKey</c> key in | ||
/// <see cref="System.Configuration.ConfigurationManager.AppSettings"/>. | ||
/// </remarks> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah I see what you mean. Ugh. Sounds good then!
r? @remi-stripe
cc @stripe/api-libraries
Modernize
StripeConfiguration
:GetFoo()
/SetFoo()
methodsHttpTimeSpan
is renamed toHttpTimeout
, becomes non-nullable, and defaults to 80 seconds (like our other libraries)ConfigurationManager.AppSettings
now works when targeting .NET Standard 2.0/v1
prefix out of the base URLs and into each service's pathUrls
internal classBreaking changes:
StripeApiVersion
is renamed toApiVersion
, and is now read-onlyThe existing
Get/Set
methods map to the new property as appropriate. Existing methods are annotated withObsolete
which will generate warnings when used, with a message indicating what to use instead.